package com.luyu.caffeinedemo.controller;

import com.luyu.caffeinedemo.config.RepeatSubmitProperty;
import com.luyu.caffeinedemo.service.MyCaffeineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @author luYuHan
 * @date 2023/8/5 15:36
 */
@RestController
@RequestMapping("/test")
public class AddressBookController {

    @Autowired
    private RepeatSubmitProperty property;

    @Autowired
    private MyCaffeineService myCaffeineService;

    /**
     * 新增
     */
    @PostMapping("/1")
    public boolean save(@RequestBody RepeatSubmitProperty person) {
        // 模拟注解获取进行判断是否重复提交的条件
        property.setKey(person.getKey());
        property.setValue(person.getValue());
        property.setTime(person.getTime());
        property.setTimeUnit(TimeUnit.SECONDS);
        // 进行判断是否重复提交
        boolean data = myCaffeineService.getData(property);
        if (data){
            throw new RuntimeException(property.getErrorMsg());
        }
        System.out.println("开发配置:"+property);
        return data;
    }


}
